<?php
/**
 * Nweb Editor
 *
 * This script is protected by copyright. Its use, copying, modification
 * and distribution without written consent of the author is prohibited.
 *
 * @category    source
 * @package     pl.nweb.editor.model
 * @subpackage  row
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2012 Krzysztof Kardasz
 * @license     http://www.gnu.org/licenses/lgpl-3.0.txt  GNU Lesser General Public
 * @version     1.0 $Id$
 * @link        https://nweb-editor.googlecode.com
 * @link        http://editor.nweb.pl
 */

namespace pl\nweb\editor\app\model\gateway\row;

use \pl\nweb\editor\app\model\gateway\table\User as Table;

/**
 * Model wiersza tabeli
 *
 * @category    source
 * @package     pl.nweb.editor.model
 * @subpackage  row
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2012 Krzysztof Kardasz
 * @version     1.0 $Id$
 */
class User extends \pl\nweb\editor\app\model\gateway\Row
{
    /**
     * Definiuje identyfikator
     *
     * @param integer $id identyfikator
     * @return void
     */
    public function setId ($id)
    {
        if($id = (int)$id) {
            $this->{Table::FIELD_ID} = $id;
        }
    }

    /**
     * Zwraca identyfikator
     *
     * @return integer
     */
    public function getId ()
    {
        return (int)$this->get(Table::FIELD_ID);
    }

    /**
     * Definiuje adres email
     *
     * @param  string $email adres email
     * @return void
     */
    public function setEmail ($email)
    {
        $this->{Table::FIELD_EMAIL} = $email;
    }

    /**
     * Zwraca adres email
     *
     * @return string
     */
    public function getEmail ()
    {
        return $this->get(Table::FIELD_EMAIL);
    }

    /**
     * Definiuje hasło
     *
     * @param  string $pass hasło
     * @return void
     */
    public function setPass ($pass)
    {
        $this->{Table::FIELD_PASS} = $pass;
    }

    /**
     * Zwraca hasło
     *
     * @return string
     */
    public function getPass ()
    {
        return $this->get(Table::FIELD_PASS);
    }

    /**
     * Definiuje sól
     *
     * @param  string $salt sól
     * @return void
     */
    public function setSalt ($salt)
    {
        $this->{Table::FIELD_SALT} = $salt;
    }

    /**
     * Zwraca sól
     *
     * @return string
     */
    public function getSalt ()
    {
        return $this->get(Table::FIELD_SALT);
    }

    /**
     * Definiuje rolę
     *
     * @param  string $role rola
     * @return void
     */
    public function setRole ($role)
    {
        $this->{Table::FIELD_ROLE} = $role;
    }

    /**
     * Zwraca rolę
     *
     * @return string
     */
    public function getRole ()
    {
        return $this->get(Table::FIELD_ROLE);
    }

    /**
     * Definiuje imię
     *
     * @param  string $firstName imię
     * @return void
     */
    public function setFirstName ($firstName)
    {
        $this->{Table::FIELD_FIRST_NAME} = $firstName;
    }

    /**
     * Zwraca imię
     *
     * @return string
     */
    public function getFirstName ()
    {
        return $this->get(Table::FIELD_FIRST_NAME);
    }

    /**
     * Definiuje nazwisko
     *
     * @param  string $lastName nazwisko
     * @return void
     */
    public function setLastName ($lastName)
    {
        $this->{Table::FIELD_LAST_NAME} = $lastName;
    }

    /**
     * Zwraca nazwisko
     *
     * @return string
     */
    public function getLastName ()
    {
        return $this->get(Table::FIELD_LAST_NAME);
    }

    /**
     * Definiuje telefon
     *
     * @param  string $phone telefon
     * @return void
     */
    public function setPhone ($phone)
    {
        $this->{Table::FIELD_PHONE} = $phone;
    }

    /**
     * Zwraca telefon
     *
     * @return string
     */
    public function getPhone ()
    {
        return $this->get(Table::FIELD_PHONE);
    }

    /**
     * Definiuje datę logowania
     *
     * @param  string $date data
     * @return void
     */
    public function setLoginTime ($date)
    {
        $this->_setDate(Table::FIELD_LOGIN_TIME, $date);
    }

    /**
     * Zwraca datę logowania
     *
     * @param  string $format format
     * @return null|string
     */
    public function getLoginTime ($format = 'Y/m/d H:i:s')
    {
        $this->_getDate(Table::FIELD_LOGIN_TIME, $format);
    }

    /**
     * Definiuje status
     *
     * @param  integer $status status
     * @return void
     */
    public function setStatus ($status)
    {
        $this->{Table::FIELD_STATUS} = (int)$status;
    }

    /**
     * Zwraca status
     *
     * @return integer
     */
    public function getStatus ()
    {
        return (int)$this->get(Table::FIELD_STATUS);
    }

    /**
     * Zwraca flagę czy jest to podany status
     *
     * @param  integer $status status
     * @return boolean
     */
    public function isStatus ($status)
    {
        return $status == $this->getStatus();
    }

    /**
     * Zwraca datę utworzenia obiektu
     *
     * @param  string $format format
     * @return null|string
     */
    public function getCreated ($format = 'Y/m/d H:i:s')
    {
        return $this->_getDate(Table::FIELD_CREATED, $format);
    }

    /**
     * Zwraca datę modyfikacji obiektu
     *
     * @param  string $format format
     * @return null|string
     */
    public function getModified ($format = 'Y/m/d H:i:s')
    {
        return $this->_getDate(Table::FIELD_MODIFIED, $format);
    }

    /**
     * Allows pre-update logic to be applied to row.
     * Subclasses may override this method.
     *
     * @return void
     */
    protected function _update()
    {
        $this->{Table::FIELD_MODIFIED} = new \Zend_Db_Expr('NOW()');
    }

    /**
     * Allows pre-insert logic to be applied to row.
     * Subclasses may override this method.
     *
     * @return void
     */
    protected function _insert()
    {
        $this->{Table::FIELD_CREATED} = new \Zend_Db_Expr('NOW()');
        $this->{Table::FIELD_MODIFIED} = new \Zend_Db_Expr('NOW()');
    }
}